﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace _1.MobilePhoneDevice
{
    public class GSM
    {
        private string phoneModel;
        private string manufacturer;
        private short price;
        private string owner;
        private Battery battery;
        private Display display;
        private int telNumber;
        private DateTime startTime = new DateTime();
        private DateTime endTime = new DateTime();
        private List<Call> calls = new List<Call>();
        private double callCost;
        // properties

        public double CallCost
        {
            get { return this.callCost; }
        }
        public List<Call> Calls
        {
            get { return this.calls; }
        }
        public DateTime EndTime
        {
            get { return this.endTime; }
        }
        public DateTime StartTime
        {
            get { return this.startTime; }
        }
        public int TelNumber
        {
            get { return this.telNumber; }
        }
        public string PhoneModel
        {
            get { return this.phoneModel; }
        }
        public string Manufacturer
        {
            get { return this.manufacturer; }
        }
        public short Price
        {
            get { return this.price; }
            set
            {
                if ((value < 0) || (value > 2000))
                {
                    throw new ArgumentException("invalid price");
                }
                else
                {
                    this.price = value;
                }
            }
        }
        public string Owner
        {
            get { return this.owner; }
            set { this.owner = value; }
        }
        // **************************************************
        // Constructors
        public GSM(string phonemodel, string manufacturer, short price, BatTypes batmodel, int colors)
        {
            this.phoneModel = phonemodel;
            this.manufacturer = manufacturer;
            this.price = price;
            this.owner = "Unknown";
            battery = new Battery(batmodel);
            display = new Display(colors);
        }
        public GSM(string phonemodel, string manufacturer, string owner, BatTypes batmodel, int colors, byte displaySize)
        {
            this.phoneModel = phonemodel;
            this.manufacturer = manufacturer;
            this.price = 0;
            this.owner = owner;
            battery = new Battery(batmodel);
            display = new Display(colors, displaySize);
        }
        public GSM(string phonemodel, string manufacturer, BatTypes batmodel, int colors, byte displaySize)
        {
            this.phoneModel = phonemodel;
            this.manufacturer = manufacturer;
            this.price = 0;
            this.owner = "Unknown";
            battery = new Battery(batmodel);
            display = new Display(colors, displaySize);
        }
        public GSM(string phonemodel, string manufacturer, short price, string owner, BatTypes batmodel, byte displaySize)
        {
            this.phoneModel = phonemodel;
            this.manufacturer = manufacturer;
            this.Price = price;
            this.Owner = owner;
            battery = new Battery(batmodel);
            display = new Display(displaySize);
        }
        public GSM(string phonemodel, string manufacturer, BatTypes batmodel, int hoursIdle, int hoursTalk, byte displaySize, int colors)
        {
            this.phoneModel = phonemodel;
            this.manufacturer = manufacturer;
            this.Price = 0;
            this.Owner = "Unknown";
            battery = new Battery(batmodel, hoursIdle, hoursTalk);
            display = new Display(colors, displaySize);
        }





        // **************************************************
        // Methods
        public override string ToString()
        {
            return "Model       : " + this.phoneModel + "\n" + "Manufacturer: " + this.manufacturer + "\n" + "Price       : " + this.price + "\n" + "Owner       : "
                + this.owner + "\n" + "BatModel    : " + this.battery.BatteryModel + "\n" + "HoursIdle   : " + this.battery.HoursIdle + "\n" + "HoursTalk   : " + this.battery.HoursTalk + "\n"
                + "Colors      : " + this.display.Colors + "\n" + "DisplauSize : " + this.display.DisplaySize;
        }

        public void DisplayGSMInfo(GSM telephone)
        {
            Console.WriteLine(telephone);
        }
        public void DisplaySpecificCall(int calNum)
        {
            // calculating cost, and printing details
            double cost = ((calls[calNum].Duration.Minutes) * calls[calNum].CallPrice) +
                ((calls[calNum].Duration.Seconds / 60.0) * calls[calNum].CallPrice) +
                ((calls[calNum].Duration.Milliseconds / 360.0) * calls[calNum].CallPrice);//calls[calNum].Duration.Minutes * this.CallPrice;
            Console.Write("   Number: {0}\nstartTime: {1}\n  endTime: {2}\n duration: {3} mins {4} secs {5} mils, cost: {6:F3} BGN\n\n",
                calls[calNum].Number, calls[calNum].StartTime, calls[calNum].EndTime, calls[calNum].Duration.Minutes,
                calls[calNum].Duration.Seconds, calls[calNum].Duration.Milliseconds, cost);

        }
        public void DisplayAllCalls()
        {
            for (int i = 0; i < calls.Count; i++)
            {
                DisplaySpecificCall(i);
            }
        }
        public void StartCall(int number, int callCost)
        {
            if (number < 0)
            {

                throw new ArgumentOutOfRangeException();

            }
            else
            {

                this.telNumber = number;
                this.callCost = callCost;
            }
            this.startTime = DateTime.Now;

        }
        public void EndCall()
        {
            this.endTime = DateTime.Now;
            Call newCall = new Call(this.telNumber, this.startTime, this.endTime, this.callCost);
            calls.Add(newCall);
        }
        public void ClearCallList()
        {
            calls.RemoveRange(0, calls.Count);
        }
        public void DeleteCall(int number)
        {
            calls.RemoveAt(number - 1);
        }

    }
    // **************************************************
    class MobilePhoneDevice
    {
        static void Main()
        {
            Console.SetWindowSize(70, 61);
            GSM telOne = new GSM("Alcatel", "China", 50, "Ivan", BatTypes.LiIon, 123);
            GSM telTwo = new GSM("Nokia", "Japan", BatTypes.Alcal, 113, 311, 10, 31030);
            Console.WriteLine("Current telephones are:\ntel 1:\n ");
            telOne.DisplayGSMInfo(telOne);
            Console.WriteLine();
            Console.WriteLine("And tel 2:\n");
            telTwo.DisplayGSMInfo(telTwo);
            Console.Write("press enter to start calls");
            Console.ReadLine();
            try
            {
                Console.WriteLine("telOne calling.....111111111");
                telOne.StartCall(111111111, 11);
                System.Threading.Thread.Sleep(1100);
                Console.WriteLine("end call");
                telOne.EndCall();
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine("invalid number");
            }

            telOne.StartCall(222222222, 11);
            Console.WriteLine("telOne calling.....222222222");
            System.Threading.Thread.Sleep(1100);
            Console.WriteLine("end call");
            telOne.EndCall();

            telOne.StartCall(333333333, 14);
            Console.WriteLine("telOne calling.....333333333");
            System.Threading.Thread.Sleep(3200);
            Console.WriteLine("end call");
            telOne.EndCall();

            telOne.StartCall(444444444, 10);
            Console.WriteLine("telOne calling.....444444444");
            System.Threading.Thread.Sleep(500);
            Console.WriteLine("end call");
            telOne.EndCall();

            telOne.StartCall(555555555, 15);
            Console.WriteLine("telOne calling.....555555555");
            System.Threading.Thread.Sleep(10);
            Console.WriteLine("end call");
            telOne.EndCall();

            telTwo.StartCall(121212121, 11);
            Console.WriteLine("telTwo calling.....121212121");
            System.Threading.Thread.Sleep(500);
            Console.WriteLine("end call");
            telTwo.EndCall();

            telTwo.StartCall(232323232, 5);
            Console.WriteLine("telTwo calling.....232323232");
            System.Threading.Thread.Sleep(500);
            Console.WriteLine("end call");
            telTwo.EndCall();

            telTwo.StartCall(343434343, 11);
            Console.WriteLine("telTwo calling.....343434343");
            System.Threading.Thread.Sleep(500);
            Console.WriteLine("end call\n");
            telTwo.EndCall();
            Console.Write("press enter for more details");
            Console.ReadLine();
            Console.WriteLine("**********************************");
            Console.WriteLine("telOne all calls list\n");
            telOne.DisplayAllCalls();

            Console.WriteLine("deleting call 2\n");
            telOne.DeleteCall(2);

            Console.WriteLine("telOne all calls list again\n");
            telOne.DisplayAllCalls();

            Console.WriteLine("**********************************");
            Console.WriteLine("telTwo all calls list\n");
            telTwo.DisplayAllCalls();
            Console.WriteLine("**********************************");
            Console.WriteLine("telTwo only call 1");
            telTwo.DisplaySpecificCall(1);
            Console.WriteLine("**********************************");
            Console.WriteLine("clear telTwo calls");
            telTwo.ClearCallList();

            Console.WriteLine("telTwo all calls list again\n");
            telTwo.DisplayAllCalls();

            //tele1.DisplaySpecificCall(1);
            //tele2.DisplaySpecificCall(0);
        }
    }
}
